<template>
	<om-addpage style="padding-top: 35px;" :busCode="busCode" :menuName="menuName" @formSubmit="formSubmit">
		<om-autoform ref="autoform" :initConfigData="mainConfigData" :initValue="initValue"></om-autoform>
	</om-addpage>
</template>

<script>
	import {
		errorModal,
		ignoreHtml,
		getUrl,
		confirmModal,
		ptFloat,
		minusF
	} from '@/static/js/common.js';
	import {
		buildFormData,
		formValidation,
		tranferToEditors,
		changeEditor,
		setSubmitSubValue,
		configSelectData,
		hasValue,
		formShowLoading,
		getFormFields,
		formModelLoad,
		getWorkCacheKey
	} from '@/static/js/formUtil.js';
	import urlUtil from '@/static/js/urlUtil.js';
	import { mapState } from 'pinia';
	import {useLoginUserStore} from '@/stores/login-user.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildFormData({
				infoCache:'hr-cg-trApply-info-cache'
			})
		},
		computed: {
			...mapState(useLoginUserStore, ['userName', 'userId'])
		},
		methods:{
			getWorkParam(){
				let _that = this
				return {
					infonameId:_that.$refs.autoform.formdata.infonameId
				}
			},
			formSubmit(){
				let _that = this
				_that.om.formSave("trApply/addTrApply",_that.formdata,_that)
			},
			getInfoList1(id){
				let _that = this
				_that.om.request(
					"tworkInfo/getInfo1",
					{
						userId:id
					}
				).then(res=>{
					_that.subEditorObj["workInfo"].workList = res.value
				})
			},
			getInfo(id){
				let _that = this
				_that.om.request(
					"tuserInfo/getInfo",
					{
						userId:id
					}
				).then(res=>{
					_that.$refs.autoform.formdata.userno =res.value.userno
					_that.$refs.autoform.formdata.infosex = res.value.sexName
					_that.$refs.autoform.formdata.infoeducation =res.value.edu
					_that.$refs.autoform.formdata.infoentrytime = res.value.entrytime
					_that.$refs.autoform.formdata.infophone = res.value.phone
					_that.$refs.autoform.formdata.infobirthplace = res.value.birthplace
				})
			},
			initLoad(options){
				let _that = this
				let ajaxArr = [
					{
						url:'tuserInfo/getInfo',
						param:{
							userId:_that.userId
						}
					},
					urlUtil.dictZeroComboboxUrl("37136"),
					{
						url:'/commonForm/hasMainPos',
						param:{
							busCode:options.code
						}
					}
				]
				formModelLoad(ajaxArr,function(res,mainData){
					changeEditor("topinfo","zuserId",{
						defaultValue:_that.userId,
						defaultName:_that.userName
					},null,mainData)
					changeEditor("userInfo","userno",{
						defaultName:res[0].value.userno
					},null,mainData)
					changeEditor("userInfo","infonameId",{
						defaultValue:_that.userId,
						defaultName:_that.userName
					},null,mainData)
					if(res[2].value){
						changeEditor("userInfo","infonameId",'type','linkbox',mainData)
						changeEditor("userInfo","infonameId",{
							"link":'../../public/searchUser/searchUser',
							"linkParam": {
								cachename: _that.infoCache,
								isSingle:true
							}
						},null,mainData)
					}else{
						changeEditor("userInfo","infonameId",'type','labelbox',mainData)
					}
					changeEditor("userInfo","infosex",{
						defaultName:res[0].value.sexName
					},null,mainData)
					changeEditor("userInfo","infoeducation",{
						defaultName:res[0].value.edu
					},null,mainData)
					changeEditor("userInfo","infoentrytime",{
						defaultName:res[0].value.entrytime
					},null,mainData)
					changeEditor("userInfo","infophone",{
						defaultName:res[0].value.phone
					},null,mainData)
					changeEditor("userInfo","infobirthplace",{
						defaultName:res[0].value.birthplace
					},null,mainData)
					changeEditor("resignInfo","resignCode","data",configSelectData(res[1],"code","dicname"),mainData)
					if(_that.subEditorObj["workInfo"]){
						changeEditor("workInfo","objStr1",{
							showAdd:false,
							showDel:false,
							showArrow:false,
							titleTemplate:"<%=posName || '无'%>|<%=workWayName || '无'%>|<%=instShort || '无'%>",
							subtitle1Template:"<%=parentInst || '无'%>|<%=posCareercat || '无'%>|<%=posLevel || '无'%>",
							subtitle2Template:"<%=salaryWay || '无'%>|<%=workDate || '无'%>"
						},null,mainData)
					}
					if(_that.subEditorObj["applyResignPosInfo"]){
						changeEditor("applyResignPosInfo","objStr",{
							getWorkParam:'getWorkParam',
							titleTemplate:"<%=posName || '无'%>",
							subtitle1Template:"<%=instShortName || '无'%>|<%=orgShortName || '无'%>",
							subtitle2Template:"<%=handleWayName || '无'%>|<%=effectDate || '无'%>"
						},null,mainData)
					}
					_that.$nextTick(function(){
						_that.getInfoList1(_that.userId)
					})
					
				},options)
			}
		},
		onLoad(options) {
			let _that = this
			_that.initLoad(options)
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				for(var fieldId in _that.subEditorObj){
					var editor = _that.subEditorObj[fieldId]
					uni.getStorage({
						key: getWorkCacheKey(fieldId),
						success: function(res) {
							editor.workList = res.data;
							uni.removeStorage({
								key: getWorkCacheKey(fieldId)
							});
						}
					});
				}
				uni.getStorage({
					key:_that.infoCache,
					success:(res)=>{
						if(res.data){
							let d = res.data[0]
							let formdata = _that.$refs.autoform.formdata
							formdata.infonameId = d.id
							formdata.userName = d.username
							_that.getInfoList1(d.id)
							_that.getInfo(d.id)
							_that.subEditorObj["applyResignPosInfo"].workList = []
							uni.removeStorage({
								key:_that.infoCache
							})
						}
					}
				})
			}
		}
	}
</script>

<style></style>                                                                                                                                                                                                                                                                                                                                      
